package com.banyuan.项目;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class ServerSet extends JDialog {
    private String port;
    private JTextField textField_1;

    /**
     * Launch the application.
     */
	/*public static void main(String[] args) {
		try {
			ServerSet dialog = new ServerSet();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/

    //返回一个端口的字符串，注意会不会返回一个null；
   /* public String window() {
        try {
            ServerSet dialog = new ServerSet();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return port;
    }*/

    public String getPort() {
        return port;
    }

    /**
     * Create the dialog.
     */
    public ServerSet() {
        setTitle("服务器设置");
        setBounds(100, 100, 368, 161);
        getContentPane().setLayout(null);
        {
            JButton okButton = new JButton("OK");

            //这边做出一个判断，当文本域不为空时可以
           /* if (textField_1.getText() != null) {
                okButton.addActionListener((e) -> {
                    port = textField_1.getText();
                });
            }*/
            okButton.addActionListener((e) -> {
                port = textField_1.getText();
                this.setVisible(false);
            });
            okButton.setBounds(82, 93, 75, 29);
            getContentPane().add(okButton);
            okButton.setActionCommand("OK");
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener((e) -> {
                this.setVisible(false);
            });
            cancelButton.setBounds(169, 93, 86, 29);
            getContentPane().add(cancelButton);
            cancelButton.setActionCommand("Cancel");
        }
        {
            JLabel lblip = new JLabel("请输入端口号：");
            lblip.setHorizontalAlignment(SwingConstants.RIGHT);
            lblip.setBounds(59, 31, 98, 29);
            getContentPane().add(lblip);
        }
        {
            textField_1 = new JTextField();
            textField_1.setColumns(10);
            textField_1.setBounds(169, 31, 150, 28);
            getContentPane().add(textField_1);
        }
    }

}
